package com.wkh.generator;

import com.wkh.model.MainTemplateConfig;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.IOException;

/**
 * @author wkh
 * 核心生成器
 */
public class MainGenerator {

    /*public static void main(String[] args) {

        //静态文件生成
        //D:\code\xinyuanyi-generator\xinyuanyi-generator-basic
        String property = System.getProperty("user.dir");
        String parentPath = new File(property).getParent();
        //模板路径
        String inputPath = new File(parentPath, "xinyuanyi-generator-demo-projects"+File.separatorChar+"acm-template").getPath();
        StaticGenerator.copyFilesByRecursion(inputPath,property);
        //acm-template/src/com/yupi/acm
        //动态文件生成
        String propertyDynamically = System.getProperty("user.dir");
        String inputPathDynamically = property + File.separatorChar + "src/main/resources/templates/MainTemplate.java.ftl";
        String outputPathDynamically = property + File.separatorChar + "acm-template/src/com/yupi/acm/MainTemplate.java";
        MainTemplateConfig model = new MainTemplateConfig("wkh", "和为", false);
        try {
            DynamicallyGenerated.doGenerator(inputPathDynamically,outputPathDynamically,model);
        } catch (Exception e) {
            e.printStackTrace();

        }
    }*/

    public static void doGenerator(Object model){
        String propertyPath = System.getProperty("user.dir");
        File parentFile = new File(propertyPath).getParentFile();
        String inputPath = new File(parentFile, "xinyuanyi-generator-demo-projects"+File.separatorChar+"acm-template").getPath();
        String outPutPath = propertyPath;
        //静态文件生成
        StaticGenerator.copyFilesByRecursion(inputPath,outPutPath);

        //拿到模板文件的路径
        String inputPathDynamically = propertyPath + File.separatorChar + "src/main/resources/templates/MainTemplate.java.ftl";
        //生成的文件的路径
        String outputPathDynamically = outPutPath + File.separatorChar + "acm-template/src/com/yupi/acm/MainTemplate.java";
        //生成动态文件
        try {
            DynamicallyGenerated.doGenerator(inputPathDynamically,outputPathDynamically,model);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
